<% add_decidim_page_title(t("admin.index.title", scope: "decidim.verifications.csv_census")) %>

<div class="card">
  <div class="item_show__header item_show__header--with-action-options">
    <h1 class="item_show__header-title">
      <%= t("index.title", scope: "decidim.verifications.csv_census.admin") %>
      <%= link_to t("index.import_csv", scope: "decidim.verifications.csv_census.admin"), new_import_census_logs_path, method: :get, class: "button button__sm button__transparent-secondary" %>
      <button type="button" data-action="csv_census-record" data-census-dialog="census_drawer" data-census-url="<%= new_record_census_logs_path %>" class="button button__sm button__secondary">
        <%= t("index.add_new_record_button", scope: "decidim.verifications.csv_census.admin") %>
      </button>
    </h1>
  </div>
  <% if csv_census_data.any? %>
    <div class="table-stacked mt-8">
      <table class="table-list">
        <thead>
          <tr>
            <th><%= t("index.fields.email", scope: "decidim.verifications.csv_census.admin") %></th>
            <th><%= t("index.fields.created_at", scope: "decidim.verifications.csv_census.admin") %></th>
            <th><%= t("index.fields.user_authorized", scope: "decidim.verifications.csv_census.admin") %></th>
            <th><%= t("index.fields.actions", scope: "decidim.verifications.csv_census.admin") %></th>
          </tr>
        </thead>
        <tbody>
          <% csv_census_data.each do |data| %>
            <tr>
              <td data-label="<%= t("index.fields.email", scope: "decidim.verifications.csv_census.admin") %>">
                <%= data.email %>
              </td>
              <td data-label="<%= t("index.fields.created_at", scope: "decidim.verifications.csv_census.admin") %>">
                <%= l data.created_at, format: :decidim_short %>
              </td>
              <td data-label="<%= t("index.fields.user_authorized", scope: "decidim.verifications.csv_census.admin") %>" class="custom-text-align">
                <% last_login_info = last_login(data) || { icon: nil, text: t(".no_user"), last_sign_in: nil } %>
                <% if last_login_info[:icon].present? %>
                  <%= icon_with_tooltip(last_login_info[:icon], last_login_info[:text]) %>
                <% else %>
                  <%= last_login_info[:text] || t(".no_user") %>
                <% end %>
                <%= last_login_info[:last_sign_in] %>
              </td>
              <td data-label="<%= t("index.fields.actions", scope: "decidim.verifications.csv_census.admin") %>" class="table-list__actions">
                <button type="button" data-controller="dropdown" data-target="actions-census-log-<%= data.id %>" aria-label="<%= t("decidim.admin.actions.actions_label", resource: data.id) %>">
                  <%= icon "more-fill", class: "text-secondary" %>
                </button>

                <div class="inline-block relative">
                  <ul id="actions-census-log-<%= data.id %>" class="dropdown dropdown__action" aria-hidden="true">
                    <li class="dropdown__item">
                      <%= link_to "#", class: "dropdown__button", data: { action: "csv_census-record", census_dialog: "census_drawer", census_url: edit_record_census_log_path(data) } do %>
                        <%= icon "pencil-line" %>
                        <%= t("actions.edit", scope: "decidim.verifications.csv_census.admin") %>
                      <% end %>
                    </li>

                    <hr>

                    <li class="dropdown__item">
                      <%= link_to census_log_path(data), method: :delete, data: { confirm: t("actions.confirm_destroy", scope: "decidim.verifications.csv_census.admin") }, class: "dropdown__button" do %>
                        <%= icon "delete-bin-line" %>
                        <%= t("actions.destroy", scope: "decidim.verifications.csv_census.admin") %>
                      <% end %>
                    </li>
                  </ul>
                </div>
              </td>
            </tr>
          <% end %>
        </tbody>
      </table>
    </div>
  <% else %>
    <p><%= t(".empty", import_csv: link_to(t("index.import_csv", scope: "decidim.verifications.csv_census.admin"), new_import_census_logs_path, class: " decoration-solid decoration-secondary font-semibold text-secondary").html_safe).html_safe %></p>
  <% end %>
</div>
<%= decidim_paginate csv_census_data %>

<%= render partial: "csv_census_drawer" %>

<%= append_javascript_pack_tag "decidim_verifications" %>
<%= append_stylesheet_pack_tag "decidim_verifications" %>
